﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Input;
using SilentWebsite.Model;
using SilentWebsite.ViewModels.Commands;
using SilentWebsite.ViewModels.Helpers;
using SilentWebsite.Views.Windows;
using SilentWebsite.Web;

namespace SilentWebsite.ViewModels.Windows
{
    public class RegisterViewModel : ViewModelBase, INotifyDataErrorInfo
    {
        public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
        public bool HasErrors { get; private set; }

        public ICommand Register { get; set; }
        public ICommand Cancel { get; set; }

        public string Email { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public string PasswordConfirm { get; set; }
        public string Location { get; set; }

        private readonly RegisterChild registerWindow;

        public RegisterViewModel(RegisterChild window) : base("Register")
        {
            registerWindow = window;
            Register = new SimpleCommand(RegisterUser);
            Cancel = new SimpleCommand(registerWindow.Close);
        }

        private void RegisterUser()
        {
            var user = new User
                {
                    UserName = Username,
                    Email = Email,
                    Password = Password,
                    City = string.Empty,
                    Country = string.Empty,
                    DateOfBirth = DateTime.Now,
                    FullName = string.Empty,
                };
            SilentEngine.Instance.Accounts.CreateAccount(user);
            registerWindow.Close();
            NavigationService.Navigate("start");
        }

        public IEnumerable GetErrors(string propertyName)
        {
            return new List<object>();
        }
    }
}
